using System;
using System.Collections.Generic;
using System.Text;

namespace CodeFactory.IDAL
{
    [Serializable]
    public class ConnectionInfo
    {
        [NonSerialized]
        private string connectionString;

        [NonSerialized]
        private DatabaseType type;

        [NonSerialized]
        private string provider;

        [NonSerialized]
        private string dbPath;

        [NonSerialized]
        private string server;

        [NonSerialized]
        private string user;

        [NonSerialized]
        private string password;

        [NonSerialized]
        private int port;

        [NonSerialized]
        private string database;

        public ConnectionInfo()
        {
            this.connectionString = string.Empty;
            this.database = string.Empty;
            this.dbPath = string.Empty;
            this.password = string.Empty;
            this.port = -1;
            this.provider = string.Empty;
            this.server = string.Empty;
            this.type = DatabaseType.File;
            this.user = string.Empty;
        }

        public bool Equals(ConnectionInfo info)
        {
            if (info.Type != this.type)
                return false;
            if (this.type == DatabaseType.File)
            {
                if (this.dbPath == info.DbPath)
                    return true;
                else
                    return false;
            }
            else
            {
                if (this.server == info.Server && this.port == info.Port &&
                    this.user == info.User && this.password == info.Password &&
                    this.database == info.Database)
                    return true;
                else
                    return false;
            }
        }

        public string ConnectionString
        {
            get { return this.connectionString; }
            set { this.connectionString = value; }
        }

        public DatabaseType Type
        {
            get { return this.type; }
            set { this.type = value; }
        }

        public string Provider
        {
            get { return this.provider; }
            set { this.provider = value; }
        }

        public string DbPath
        {
            get { return this.dbPath; }
            set { this.dbPath = value; }
        }

        public string Server
        {
            get { return this.server; }
            set { this.server = value; }
        }

        public string User
        {
            get { return this.user; }
            set { this.user = value; }
        }

        public string Password
        {
            get { return this.password; }
            set { this.password = value; }
        }

        public int Port
        {
            get { return this.port; }
            set { this.port = value; }
        }

        public string Database
        {
            get { return this.database; }
            set { this.database = value; }
        }
    }
}
